#coding=utf8
from django.forms import ModelForm
from django.forms.widgets import *
from django import forms
from django.contrib.auth.models import *

from docshare.share.models import *

class UpFileForm(ModelForm):
    name = forms.CharField(max_length=255,widget=forms.TextInput(attrs={'class':'text','style':'WIDTH: 330px;float:left;'}))
    about = forms.CharField(max_length=255,widget=forms.Textarea(attrs={'class':'text','style':'float:left;'}))
    cata = forms.ModelChoiceField(empty_label=None,queryset=catalog.objects.exclude(parentId=0))
    prefix_one = forms.ModelChoiceField(empty_label=None,required=True,queryset=dictionaries.objects.filter(type__contains='prefix_one'),widget=forms.Select(attrs={'style':'WIDTH: 150px;'}))
    prefix_two = forms.ModelChoiceField(empty_label=None,required=True,queryset=dictionaries.objects.filter(type__contains='prefix_two'),widget=forms.Select(attrs={'style':'WIDTH: 150px;'}))
    prefix_three = forms.ModelChoiceField(empty_label=None,required=True,queryset=dictionaries.objects.filter(type__contains='city'),widget=forms.Select(attrs={'style':'WIDTH: 150px;'}))#    可增加此参数自定义错误信息
#    error_messages={
#        'required':'前缀三不能为空！',
#    }
    class Meta:
        model = upFile
        exclude =('user','size','datetime')

class ModifFileForm(ModelForm):
    name = forms.CharField(max_length=255,widget=forms.TextInput(attrs={'class':'text','style':'WIDTH: 330px;float:left;'}))
    about = forms.CharField(max_length=255,widget=forms.Textarea(attrs={'class':'text','style':'float:left;'}))
    cata = forms.ModelChoiceField(empty_label=None,queryset=catalog.objects.exclude(parentId=0))
    prefix_one = forms.ModelChoiceField(empty_label=None,required=True,queryset=dictionaries.objects.filter(type__contains='prefix_one'),widget=forms.Select(attrs={'style':'WIDTH: 150px;'}))
    prefix_two = forms.ModelChoiceField(empty_label=None,required=True,queryset=dictionaries.objects.filter(type__contains='prefix_two'),widget=forms.Select(attrs={'style':'WIDTH: 150px;'}))
    prefix_three = forms.ModelChoiceField(empty_label=None,required=True,queryset=dictionaries.objects.filter(type__contains='city'),widget=forms.Select(attrs={'style':'WIDTH: 150px;'}))#    可增加此参数自定义错误信息
    class Meta:
        model = upFile
        exclude =('user','size','datetime','filepic','filepath')

class CataUpFileForm(ModelForm):
    name = forms.CharField(max_length=255,widget=forms.TextInput(attrs={'class':'text','style':'WIDTH: 330px;float:left;'}))
    about = forms.CharField(max_length=255,widget=forms.Textarea(attrs={'class':'text','style':'float:left;height:50px;'}))
    prefix_one = forms.ModelChoiceField(empty_label=None,required=True,queryset=dictionaries.objects.filter(type__contains='prefix_one'),widget=forms.Select(attrs={'style':'WIDTH: 150px;'}))
    prefix_two = forms.ModelChoiceField(empty_label=None,required=True,queryset=dictionaries.objects.filter(type__contains='prefix_two'),widget=forms.Select(attrs={'style':'WIDTH: 150px;'}))
    prefix_three = forms.ModelChoiceField(empty_label=None,required=True,queryset=dictionaries.objects.filter(type__contains='city'),widget=forms.Select(attrs={'style':'WIDTH: 150px;'}))#    可增加此参数自定义错误信息

    class Meta:
        model = upFile
        exclude =('user','size','datetime','cata')

class SearchForm(ModelForm):
    cata = forms.ModelChoiceField(empty_label='---企业品牌---',queryset=catalog.objects.exclude(parentId=0),widget=forms.Select(attrs={'style':'WIDTH: 150px;'}))
    prefix_two = forms.ModelChoiceField(empty_label='---宣传类型---',queryset=dictionaries.objects.filter(type__contains='prefix_two'),widget=forms.Select(attrs={'style':'WIDTH: 150px;'}))
    prefix_three = forms.ModelChoiceField(empty_label='---适用区域---',queryset=dictionaries.objects.filter(type__contains='city'),widget=forms.Select(attrs={'style':'WIDTH: 150px;'}))#    可增加此参数自定义错误信息
    class Meta:
        model = upFile

class PubForm(ModelForm):
    name = forms.CharField(max_length=50,widget=forms.TextInput(attrs={'class':'text','style':''}))
    info = forms.CharField(max_length=255,widget=forms.Textarea(attrs={'class':'text','style':'float:left;'}))
    class Meta:
        model = pub
        exclude =('user','date')

class CataForm(ModelForm):
    name = forms.CharField(max_length=50,widget=forms.TextInput(attrs={'class':'text','style':''}))
    class Meta:
        model = catalog
        exclude =('parentId')

class DictForm(ModelForm):
    type = forms.CharField(max_length=50,widget=forms.TextInput(attrs={'class':'text','style':''}))
    name = forms.CharField(max_length=50,widget=forms.TextInput(attrs={'class':'text','style':''}))
    memo = forms.CharField(max_length=255,widget=forms.Textarea(attrs={'class':'text','style':'float:left;'}))
    class Meta:
        model = dictionaries


class UserForm(ModelForm):
    groups = forms.ModelMultipleChoiceField(queryset=Group.objects.all(),widget=forms.SelectMultiple(attrs={'style':'WIDTH: 150px;'}))
    #groups = forms.ModelMultipleChoiceField(queryset=Group.objects.all())
    class Meta:
        model = User
        exclude =('password','last_login','date_joined')

class ProfileForm(ModelForm):
    class Meta:
        model = profile
        exclude =('user',)

class GroupForm(ModelForm):
    class Meta:
        model = Group

class SubForm(ModelForm):
    class Meta:
        model = subject
        exclude =('author','read_nums','repe_nums')

class ReplyForm(ModelForm):
    class Meta:
        model = reply
        exclude =('subject','author')
